// const parse = require('csv-parse').parse;
// const fs = require('fs');
const vscode = require('vscode');
const tokens = require('../res/pacenote_view.json');
let tokenTypes = Array.from(new Set(tokens.map(token => token.type)));
tokenTypes.push('comment');
tokenTypes.push("ATTRIBUTE");
tokenTypes.push("ATTRIBUTE_VALUE");
tokenTypes.push("ATTRIBUTE_NOT_SUPPORTED");
tokenTypes.push("DISTANCE");
tokenTypes.push("UNKNOWN");

//markdown string
for (let token of tokens) {
    token.markdown = new vscode.MarkdownString(`### ${token.filenames} : ${token.type}\n\n${token.description}`);
}

let tokenMap = {
    "CORNERS": vscode.CompletionItemKind.Class,
    "MODIFIER": vscode.CompletionItemKind.Interface,
    "LINKS": vscode.CompletionItemKind.Operator,
    "ADJECTIVES": vscode.CompletionItemKind.Struct,
    "ROAD": vscode.CompletionItemKind.Method,
    "LINE": vscode.CompletionItemKind.Property,
    "OBSTACLES": vscode.CompletionItemKind.Variable,
    "CONSTRUCTION": vscode.CompletionItemKind.Constant,
    "CAUTIONS": vscode.CompletionItemKind.Enum,
    "DRIVING": vscode.CompletionItemKind.Function,
    "PREPOSITIONS": vscode.CompletionItemKind.Keyword,
    "SURFACE": vscode.CompletionItemKind.Module,
    "NUMBERS": vscode.CompletionItemKind.EnumMember,
    "MISC": vscode.CompletionItemKind.Constant,
    "SYSTEM": vscode.CompletionItemKind.Text,
    "ATTRIBUTE": vscode.CompletionItemKind.Reference,
    "ATTRIBUTE_VALUE": vscode.CompletionItemKind.Unit,
    "DISTANCE": vscode.CompletionItemKind.Value
};

let ztmz_tokens_dict = {};
for (let ztmz_token of tokens) {
    let ztmz_token_filenames = ztmz_token.filenames.split(',');
    for (let filename of ztmz_token_filenames) {
        ztmz_tokens_dict[filename] = ztmz_token;
    }
}

let attributes = [
    {
        name: "@author",
        detail: "ATTRIBUTE",
        description: "The authors of the pacenote"
    },
    {
        name: "@dynamic",
        detail: "ATTRIBUTE",
        description: "The dynamic attribute, write this attribute to indicate that the pacenote is dynamic"
    },
    {
        name: "@date",
        detail: "ATTRIBUTE",
        description: "The date of the pacenote"
    }
]
let attributeDict = {};
for (let attribute of attributes) {
    attributeDict[attribute.name] = attribute;
}

module.exports = {
    tokens,
    tokenTypes,
    tokenDict: ztmz_tokens_dict,
    attributes,
    attributeDict,
    tokenMap
}